﻿/*****************************************
 * File Name:   Main.js
 * Author:      Chen Xin
 * Version:     1.0
 * Date:        2006-09-22
 * Description: 
 *****************************************/

var leftBar;
var legend;
var dropDownBiz;
var planterInfo;
var m_zoomIn;
var m_zoomOut;
var m_move;
var m_txtXCoord;
var m_txtYCoord;
var m_imgLoading;
var m_imgMapCanvas;
var canvasWidth;
var m_mapViewer;
var m_divMapBorder;
var m_divZoomBox;
var	m_hvMinX;
var	m_hvMinY;
var	m_hvMaxX;
var	m_hvMaxY;
var	m_hvMinXDef;
var	m_hvMinYDef;
var	m_hvMaxXDef;
var	m_hvMaxYDef;
var m_hvMapPage;
var m_zbxZoom;
var m_iToolMode;
var m_ExtentWidths = new Array(0.005, 0.015, 0.035, 0.1, 0.3, 0.75, 2, 6, 10, 30, 110);
var m_sClientBrowserType;
var m_sClientPlatform;


if (navigator.appName.indexOf("Netscape")>=0) {
    m_sClientBrowserType = 'Netscape';
} else if (navigator.appName.indexOf('Microsoft') >=0) {
    m_sClientBrowserType = 'IE';
} else {
    window.location = "unsupported.htm";
}

if (navigator.userAgent.indexOf("Win") >= 0) {
    m_sClientPlatform = 'Windows';
} else if (navigator.platform.indexOf("Mac") >= 0) {
    m_sClientPlatform = 'Mac';
} else {
    window.location = "unsupported.htm";
    
}

function submit() {
    
    var sURL = m_hvMapPage.value + 
                "?XMIN=" + m_mapViewer.getExtent().getLeft() + 
			    "&YMIN=" + m_mapViewer.getExtent().getBottom() + 
			    "&XMAX=" + m_mapViewer.getExtent().getRight() + 
			    "&YMAX=" + m_mapViewer.getExtent().getTop() + 
			    "&WIDTH=" + m_mapViewer.getTagWidth() + 
			    "&HEIGHT=" + m_mapViewer.getTagHeight();
    m_imgMapCanvas.src = sURL;
    //printUrl=sURL;    
    persistExtent();
}

function persistExtent() {
	m_hvMinX.value = m_mapViewer.getExtent().getLeft();
	m_hvMinY.value = m_mapViewer.getExtent().getBottom();
	m_hvMaxX.value = m_mapViewer.getExtent().getRight();
	m_hvMaxY.value = m_mapViewer.getExtent().getTop();
}

function handleToolClick(iToolMode) {
	switch(iToolMode) {
		case 1:     //zoomin
			//m_imgMapCanvas.style.cursor = "crosshair";
			m_imgMapCanvas.style.cursor = "icons/curzoomin.cur";
			break;
		case 2:     //zoomout
		    //m_imgMapCanvas.style.cursor = "crosshair";
		    m_imgMapCanvas.style.cursor = "icons/curzoomout.cur";
		    break;
		case 3:     //pan
			//m_imgMapCanvas.style.cursor = "move";
			m_imgMapCanvas.style.cursor = "icons/curpan.cur";
			break;
		case 4:     //fullextent
		    GeoFunc.defaultMap(90);
		    m_imgMapCanvas.style.cursor = "default";
		    break;
		case 5:     //search
		    m_imgMapCanvas.style.cursor = "Help";
		    break;
		case 6:     //clear
		    m_imgMapCanvas.style.cursor = "default";
		    break;
	}
	m_iToolMode = iToolMode;
}

function reportCoords(ptReport) {
	//yang
	//2007-1-27
	//Display longtitude and latitude as dms format.
  	var dx=Math.floor(ptReport.x);
	var fx=Math.floor((ptReport.x-dx)*60);
	var mx=Math.round(((ptReport.x-dx)*60-fx)*6000)/100;    //秒位精度保留到小数点后两位
	var dy=Math.floor(ptReport.y);
	var fy=Math.floor((ptReport.y-dy)*60);
	var my=Math.round(((ptReport.y-dy)*60-fy)*6000)/100;    //秒位精度保留到小数点后两位
	
	m_txtXCoord.value = "经度: " + dx + "°" + fx + "′" + mx + '″';
	m_txtYCoord.value = "纬度: " + dy + "°" + fy + "′" + my + '″';
  	
//  m_txtXCoord = $("txtXCoord");
//	m_txtYCoord = $("txtYCoord");
//	m_txtXCoord.value = "经度: " + (Math.round(ptReport.x * 10000.0) / 10000.0).toString();
//	m_txtYCoord.value = "纬度: " + (Math.round(ptReport.y * 10000.0) / 10000.0).toString();
}


function hideWaitImage() {
    m_zbxZoom.hide();
}

function getPosition(el) {
	var left = 0;
	var top  = 0;

	while (el.offsetParent) {
		left += el.offsetLeft;
		top  += el.offsetTop;
		el    = el.offsetParent;
	}

	left += el.offsetLeft;
	top  += el.offsetTop;

	return {x:left, y:top};
}

function mouseCoords(evt) {

    var scrollLeft;
    var scrollTop;

    Position.prepare();
    scrollLeft = Position.deltaX;
    scrollTop = Position.deltaY;

	if (evt.pageX || evt.pageY) {
	    return {x:evt.pageX, y:evt.pageY};
    }
    else {
        return {
            x:evt.clientX + scrollLeft - document.body.clientLeft, 
            y:evt.clientY + scrollTop - document.body.clientTop
            }
    }
    
}

function checkLegend() {
    if (legend.childNodes.length != 0 && legend.childNodes.length != 1)
        RequestLoader.showLegend();
}


/**
* Function:    CollapseLogo
* Author:      Yang
* Version:     1.0
* Date:        2007-1-29
* Params:      No params
*/
function CollapseLogo()
{
    if (header.style.height =="90px")
    {
        header.style.height ="0px";
        header.style.display="none";
        pageFooter.style.top="590px";
        $("collapseLogo").src="Picture/OpenLogoSmall.png";
        $("collapseLogo").alt="Open Logo";
    }
    else
    {
        header.style.height ="90px";
        header.style.display ="block";
        pageFooter.style.top="680px";
        $("collapseLogo").src="Picture/CloseLogoSmall.png";
        $("collapseLogo").alt="Close Logo";
    }
}

/**
* Function:    Business Data Stats
* Author:      Yang
* Version:     1.0
* Date:        2007-2-1
* Params:      No params
*/
function statsBizData()
{
//    var bizType = $("DropDownBiz").value;
//    var bizYear = $("DropDownYear").value;
//    var bizField = $("RadioButtonOfDist").SelectedValue;

    window.open ("Stats.aspx");

}

/**
* Function:    Open the map-print page 
* Author:      Yang
* Version:     1.0
* Date:        2007-3-19
* Params:      No params
*/
function printmap()
{
    var mapHeight = $("imgMapCanvas").height + 20;
    var mapWidth = $("imgMapCanvas").width + 10;
    var printUrl = $("imgMapCanvas").src;
    var windowParam = "height=" + mapHeight + ",width=" + mapWidth + ",resizable=no";
    var windowName="打印地图";
    
    window.open(printUrl, windowName, windowParam);
}

/**
* Function:    Open the map-print page 
* Author:      Yang
* Version:     1.0
* Date:        2007-3-19
* Params:      No params
*/
function openAdjustInfo()
{
    var Url = "AdjustInfo.aspx";
    var windowName="AdjustInfo";
    var windowParam = "height=510,width=640,resizable=yes";
    window.open (Url,windowName,windowParam);


}


function refresh()
{
    var sURL = m_hvMapPage.value + 
                "?XMIN=" +m_hvMinX.value + 
			    "&YMIN=" + m_hvMinY.value + 
			    "&XMAX=" + m_hvMaxX.value + 
			    "&YMAX=" + m_hvMaxY.value + 
			    "&WIDTH=" + m_mapViewer.getTagWidth() + 
			    "&HEIGHT=" + m_mapViewer.getTagHeight();
    m_imgMapCanvas.src = sURL;
    persistExtent();
    
}

